<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./swiper/swiper-bundle.min.css">
    <script src="./swiper/swiper-bundle.min.js"></script>
    <style>
        .swiper {
            width: 564px;
            height: 315px;
        }

        .swiper img {
            width: 100%;
        }
    </style>
</head>

<body>
    <!-- 轮播图 -->

    <div class="swiper">
        <div class="swiper-wrapper">
            <!-- <div class="swiper-slide">
                <a href="">
                    <img src="" alt="">
                    2
                </a>
            </div> -->
            <!-- <div class="swiper-slide">
                <a href="">
                    <img src="" alt="">
                    2
                </a>
            </div> -->

        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>

        <!-- 如果需要导航按钮 -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>


    </div>

    <ul class="plist">
        <!-- <li>
            <a href="04-item.html">
                <h2></h2>
            </a>
        </li> -->
    </ul>

    <script type="module">
        import axios from './js/axios.min.js';
        let baseURL = 'http://localhost:3000'
        axios.defaults.baseURL = baseURL;
        /*
            立刻调用列表接口 返回商品列表数据--展示到ul中

        */
        let pagenum = 1;
        let pagesize = 10;
        async function loadList() {
            let productListAPI = '/api/front/articles';
            let { data } = await axios.get(productListAPI, { params: { pagenum, pagesize } });
            console.log(data.data);

            let liArr = data.data.map(v => `
                <li>
                    <a href="04-item.html?pid=${v._id}">
                        <h2>${v.title}</h2>
                    </a>
                </li>
            `);
            document.querySelector(".plist").innerHTML = liArr.join('')



        }
        loadList()


        // 调用轮图的接口 获取 轮播的内容-生成 轮播结构 

        /*
                  列表函数
              */
        async function loadSwiperList() {
            let bannersAPI = '/api/front/banners'
            let r = await axios.get(bannersAPI);
            //获取轮播的数据 数组
            console.log(r.data.data);
            let trArr = r.data.data.map(v => `
                <div class="swiper-slide">
                    <a href="${v.link}">
                        <img src="${v.coverImg}" alt="">
                        2
                    </a>
                </div>
            `);
            document.querySelector(".swiper-wrapper").innerHTML = trArr.join('')
            console.log('轮播图的结构完整了');
            console.log('swiper 给轮播结构 加 js效果');
            var mySwiper = new Swiper('.swiper', {
                // direction: 'vertical', // 垂直切换选项
                loop: true, // 循环模式选项

                // 如果需要分页器
                pagination: {
                    el: '.swiper-pagination',
                },

                // 如果需要前进后退按钮
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                },


            })

        }

        loadSwiperList()


        setTimeout(() => {
            // var mySwiper = new Swiper('.swiper', {
            //     // direction: 'vertical', // 垂直切换选项
            //     loop: true, // 循环模式选项

            //     // 如果需要分页器
            //     pagination: {
            //         el: '.swiper-pagination',
            //     },

            //     // 如果需要前进后退按钮
            //     navigation: {
            //         nextEl: '.swiper-button-next',
            //         prevEl: '.swiper-button-prev',
            //     },


            // })
        }, 1000);



        // console.log('swiper 给轮播结构 加 js效果');
        // var mySwiper = new Swiper('.swiper', {
        //     // direction: 'vertical', // 垂直切换选项
        //     loop: true, // 循环模式选项

        //     // 如果需要分页器
        //     pagination: {
        //         el: '.swiper-pagination',
        //     },

        //     // 如果需要前进后退按钮
        //     navigation: {
        //         nextEl: '.swiper-button-next',
        //         prevEl: '.swiper-button-prev',
        //     },


        // })        
    </script>

</body>

</html>